package com.beemans.common.utils.permissions

import android.content.Context
import androidx.appcompat.app.AlertDialog
import com.beemans.common.R

/**
 * @author tiamosu
 * @date 2021/7/14.
 */
object PermissionDialog {

    /**
     * 显示授权对话框
     */
    fun showPermissionDialog(
        context: Context,
        deniedList: List<String>,
        onNegativeAction: () -> Unit = {},
        onPositiveAction: () -> Unit = {}
    ) {
        val permissionHint =
            PermissionNameConvert.getPermissionHint(context, *deniedList.toTypedArray())
        AlertDialog.Builder(context)
            .setCancelable(false)
            .setTitle(R.string.common_permission_alert)
            .setMessage(permissionHint)
            .setPositiveButton(R.string.common_permission_goto_setting_page) { dialog, _ ->
                dialog.dismiss()
                onPositiveAction.invoke()
            }
            .setNegativeButton(R.string.common_permission_cancel) { dialog, _ ->
                dialog.dismiss()
                onNegativeAction.invoke()
            }
            .show()
    }
}